<template>
<span>登陆成功，跳转至相应页面</span>
</template>

<script>
  import request from '../../utils/request'
  import wechat from '../../assets/js/weixinjs'
  export default {
      methods: {
        init() {
          let regorg = localStorage.getItem('regrog')
          if (regorg == null || regorg === 'undefined' || regorg === '') {
            regorg = '110106'
          }
          wechat.wechatLogin(this.doLogin, regorg)
        },
        doLogin() {
          let lastToken = localStorage.getItem('nowToken')
          let nowToken = this.$route.query.token
          if (lastToken) {
            localStorage.setItem('lastToken', lastToken)
          }
          localStorage.setItem('nowToken', nowToken)
          let code = wechat.GetQueryString('code')
          request.get('/interface/out/wechat/loginRedirect.do', {
            uid: this.$route.query.uid,
            regorg: localStorage.getItem('regorg'),
            code: code
          }).then((response) => {
            if (response.data.result === 'error') {
              this.$ErrorAlert(response.data.message)
            } else if (response.data.result === 'success') {
              if (response.data.data !== 'no') {
                let regorg = localStorage.getItem('regorg')
                localStorage.setItem('openId_' + regorg, response.data.data)
              }
              this.$store.commit('setLoginState', true)
              this.$router.push(this.$route.query.out_extra)
            }
          })
        }
      },
      mounted() {
        this.doLogin()
      }
    }
</script>

<style scoped>

</style>
